package com.handinfo.android.ui.window;

/**
 * 
 * @author Xiaoyingying
 * 
 * 抽奖
 * 
 */

import java.io.DataInputStream;
import java.io.IOException;

import android.graphics.Bitmap;
import android.graphics.Color;

import com.handinfo.android.DWGameManager;
import com.handinfo.android.core.graphics.DWFont;
import com.handinfo.android.core.graphics.DWGraphics;
import com.handinfo.android.core.object.Actor;
import com.handinfo.android.core.object.Animation;
import com.handinfo.android.game.IIcon;
import com.handinfo.android.game.IconManger;
import com.handinfo.android.ui.IUIWindows;
import com.handinfo.android.ui.UIWindows;
import com.handinfo.android.uicontrols.DWControlsManager;
import com.handinfo.android.uicontrols.DWListener;
import com.handinfo.android.uicontrols.controls.DWAnimationBox;
import com.handinfo.android.uicontrols.controls.DWBackground;
import com.handinfo.android.uicontrols.controls.DWButton;
import com.handinfo.android.uicontrols.controls.DWControl;
import com.handinfo.android.uicontrols.controls.DWFrame;
import com.handinfo.android.uicontrols.controls.DWGrid;
import com.handinfo.android.uicontrols.controls.DWImageBox;
import com.handinfo.android.uicontrols.controls.DWInputBox;
import com.handinfo.android.uicontrols.controls.DWLabel;
import com.handinfo.android.uicontrols.controls.DWMessageBox;
import com.handinfo.android.uicontrols.controls.DWTextbox;
import com.handinfo.android.uicontrols.controls.DWTitle;
import com.handinfo.android.utils.Tools;

public class UILuckDraw implements IUIWindows
{
	private Bitmap img_close;
	private Bitmap img_addnum;
	private Bitmap img_anniu;
	private Bitmap img_anxia;
	private Bitmap img_minus;
	private Bitmap img_plus;
	private Bitmap img_yuanbao;
	private Bitmap img_zhuanpan;
	private Bitmap img_start;
	private Bitmap img_grid;
	private Bitmap img_select;
	private Bitmap img_guangdian[];
	private Animation anim_select;

	private byte m_gift_trancount = 0;
	private byte m_gift_tranbuy = 0;
	private int m_gift_money = 0;
	private byte m_gift_size = 0;//抽奖物品size
	private GiftItem[] m_gift_list;
	private String m_gift_key = null;

	private static final byte GRIDSIZE = 10;

	public void init()
	{
		img_close = UIWindows.createImage("/img/newui/fanhuianniu_1.gnp");// 关闭窗口图标
		img_anniu = UIWindows.createImage("/img/newui/anniu_6.gnp");
		img_addnum = UIWindows.createImage("/img/newui/choujiangzengci_1.gnp");
		img_anxia = UIWindows.createImage("/img/newui/anniu_6ax.gnp");
		img_minus = UIWindows.createImage("/img/newui/haoyoufyan_2.gnp");
		img_plus = UIWindows.createImage("/img/newui/haoyoufyan_1.gnp");
		img_yuanbao = UIWindows.createImage("/img/newui/yuanbao_1.gnp");
		img_zhuanpan = UIWindows.createImage("/img/newui/zhuanlun_3.gnp");// /转轮背景
		img_start = UIWindows.createImage("/img/newui/kaishi_1.gnp");//开始
		img_grid = UIWindows.createImage("/img/newui/wupinlan.gnp");// 格子背景		
		img_select = UIWindows.createImage("/img/newui/yaobuff_1.gnp");//选中效果图
		anim_select = UIWindows.createAnimation("/anim/zhuanlun_1.anim");

		img_guangdian = new Bitmap[3];
		for (int i = 0; i < 3; i++)
		{
			img_guangdian[i] = UIWindows.createImage("/img/newui/guangdian_" + (i + 1) + ".gnp");
		}
	}

	public void open(byte index)
	{
		if (m_fram == null)
		{
			initFram();
		}
		if (!DWControlsManager.getInstance().contains(m_fram))
		{
			DWControlsManager.getInstance().removeOtherControl();
			DWControlsManager.getInstance().addControl(m_fram);
		}

		refreshFrame();
	}

	DWMessageBox msg;

	public void close(byte index)
	{
		if ((!m_luckStart) && (!m_lightStar))
		{
			DWControlsManager.getInstance().removeControl(m_fram);
			m_gift_list = null;
			luckStop();
		}
		else {
			if (DWControlsManager.getInstance().contains(msg))
			{
				DWControlsManager.getInstance().removeControl(msg);
				msg = null;
			}
				

			if (msg == null)
			{
				msg = new DWMessageBox("提示", "正在抽奖中，如果退出将损失一次抽奖次数，是否退出？");
				msg.addListener(new DWListener() {
					public void OnDoubleClick()
					{
					}

					public void OnClick()
					{
						switch (msg.getResult()) {
							
							case DWMessageBox.SOFTKEY_OK:
								DWControlsManager.getInstance().removeControl(m_fram);
								m_gift_list = null;
								luckStop();
							case DWMessageBox.SOFTKEY_BACK:
								DWControlsManager.getInstance().removeControl(msg);
								msg = null;
								break;
						}
					}
				});
			}
			DWControlsManager.getInstance().addControl(msg);
		}
	}

	public void dispose()
	{
	}

	public void logic()
	{
		if (m_fram != null && DWControlsManager.getInstance().contains(m_fram) && m_gift_list != null)
		{
			if (m_luckStart)
			{
				int way = (m_timer % (GRIDSIZE * m_arc1_speed)) / m_arc1_speed;
				if (way != m_selctIndex)
				{
					m_selectImg.setNearAnchor(m_giftGrid[way], Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);
					m_selctIndex = way;
					m_selectImg.setShow(true);
				}

//				if ((!m_luckSend) && (m_timer > GRIDSIZE * m_arc1_speed * 3))
//				{
//					m_luckSend = true;
//					DWGameManager.getInstance().getSendMessage().sendLuckDrawStart();
//				}

				if ((m_timer > GRIDSIZE * m_arc1_speed * 3) && m_gift_key != null
						&& m_gift_list[way].m_key.equals(m_gift_key))//如果当前选中物品时抽奖结果
				{
					m_waiteTime = System.currentTimeMillis() / 1000;
					luckStop();
					m_animation.setNearAnchor(m_giftGrid[way], Tools.LEFT_TOP, Tools.LEFT_TOP, -(m_animation
							.getShowWidth() - m_giftGrid[way].getShowWidth()) / 2,
							-(m_animation.getShowHeight() - m_giftGrid[way].getShowHeight()) / 2
									- m_animation.getShowHeight() / 2);
					m_animation.setShow(true);
//					showGift();

					m_luckSend = true;
					DWGameManager.getInstance().getSendMessage().sendLuckDrawGetResule();
				}
				m_timer++;
			}

			if (m_lightStar)
			{
				if (m_timer % 2 == 0)
				{
					for (int i = 0; i < 10; i++)
					{
						m_yellow[i].setShow(true);
						m_blue[i].setShow(false);
					}
				}
				else
				{
					for (int i = 0; i < 10; i++)
					{
						m_blue[i].setShow(true);
						m_yellow[i].setShow(false);
					}
				}

				if (!m_luckStart)
				{
					long nowTime = System.currentTimeMillis() / 1000;
					if ((nowTime - m_waiteTime) >= 3)
					{
						lightShop();
					}
					m_timer++;
				}
			}
		}
	}

	private DWFrame m_fram; //主界面
	private DWImageBox m_close; //关闭窗口
	private DWTextbox m_remaindeMsg; //剩余次数
	private DWLabel m_showMsg; //描述文字显示
	private DWButton m_addNum; //增次按钮
	private DWImageBox m_zhuanpan;
	private DWImageBox m_start;
	private DWGrid[] m_giftGrid;
	private DWImageBox m_selectImg;
	private DWAnimationBox m_animation;
	private DWImageBox[] m_white = new DWImageBox[20];
	private DWImageBox[] m_yellow = new DWImageBox[10];
	private DWImageBox[] m_blue = new DWImageBox[10];

	private void initFram()
	{
		m_fram = new DWFrame(DWGameManager.Screen_Width, DWGameManager.Screen_Height);
		m_fram.setBackgroundColor(0xb2000000);

		m_close = new DWImageBox(img_close);
		m_close.addListener(new DWListener() {
			public void OnDoubleClick()
			{
			}

			public void OnClick()
			{
				close((byte) 0);
			}
		});
		m_close.setTouchZoomIn(UIFixWindow.TOUCHZOOM, UIFixWindow.TOUCHZOOM);
		m_close.setNearAnchor(m_fram, Tools.RIGHT_TOP, Tools.RIGHT_TOP);
		m_fram.addControl(m_close);

		m_zhuanpan = new DWImageBox(img_zhuanpan);
		m_zhuanpan.setNearAnchor(m_fram, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);
		m_fram.addControl(m_zhuanpan);

		m_start = new DWImageBox(img_start);
		m_start.setNearAnchor(m_zhuanpan, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);
//		m_start.setShow(false);
//		m_start.setTouch(false);
		m_start.addListener(new DWListener() {

			public void OnDoubleClick()
			{
			}

			public void OnClick()
			{
				if (m_gift_trancount > 0)
				{
					luckStart();
					DWGameManager.getInstance().getSendMessage().sendLuckDrawStart();
				}
				else
					DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "您的抽奖次数已用完");
			}
		});
		m_fram.addControl(m_start);

		m_addNum = new DWButton("", img_addnum);
		m_addNum.setTop(true);
		m_addNum.addListener(new DWListener() {
			public void OnDoubleClick()
			{
			}

			public void OnClick()
			{
				if (m_gift_tranbuy < 1)
				{
					DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "今日增次次数已用完");
					return;
				}
				Tools.debugPrintln("m_luckStart=" + m_luckStart);
				if ((!m_luckStart) && (!m_lightStar))
					showAddNum();
				else
					DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "抽奖中");
			}
		});
		m_addNum.setNearAnchor(m_zhuanpan, Tools.LEFT_TOP, Tools.RIGHT_TOP, -(74 * img_zhuanpan.getWidth() / 466),
				110 * img_zhuanpan.getHeight() / 447);
		m_fram.addControl(m_addNum);

		DWFont m_textFront = DWFont.getFont(DWFont.getDefaultFont().getFontSize() + 3);
		String m_message = "送上节日大礼。天天过节，天天拥有好心情";
		m_showMsg = new DWLabel(m_message);
		m_showMsg.setTextColor(0xffffde65);
		m_showMsg.setFont(m_textFront);
		m_showMsg.setShowWideHigh((int) m_textFront.stringWidth(m_message), m_showMsg.getShowHeight());
		m_showMsg.setNearAnchor(m_zhuanpan, Tools.HCENTER_BOTTOM, Tools.HCENTER_BOTTOM);
		m_showMsg.setTop(true);
		m_fram.addControl(m_showMsg);

//		m_gift_size = 10;
		m_giftGrid = new DWGrid[GRIDSIZE];
		for (int i = 0; i < m_giftGrid.length; i++) {
			m_giftGrid[i] = new DWGrid(img_grid);
			m_giftGrid[i].setDarg(true);
			int m_move = m_zhuanpan.getShowHeight() * 140 / 447;
			setPoint(m_giftGrid[i], m_zhuanpan, m_move, GRIDSIZE, i);
			final int m_idnex = i;
			m_giftGrid[i].addListener(new DWListener() {
				public void OnDoubleClick()
				{
				}

				public void OnClick()
				{
					if (m_giftGrid[m_idnex].m_data != null)
						DWGameManager.getInstance().getSendMessage().sendSeeItemInfos(0, m_gift_list[m_idnex].m_key);
				}
			});
			m_fram.addControl(m_giftGrid[i]);
		}

		m_selectImg = new DWImageBox(img_select);
		m_selectImg.setTop(true);
		m_fram.addControl(m_selectImg);

		m_animation = new DWAnimationBox(new Actor(anim_select));
		m_fram.addControl(m_animation);

		//边缘转动的效果
		for (int i = 0; i < 20; i++)
		{
			m_white[i] = new DWImageBox(img_guangdian[2]);
			int m_move = m_zhuanpan.getShowHeight() * 205 / 447;
			setPoint(m_white[i], m_zhuanpan, m_move, 20, i);
			m_fram.addControl(m_white[i]);
		}

		for (int i = 0; i < 10; i++)
		{
			m_yellow[i] = new DWImageBox(img_guangdian[0]);
			m_blue[i] = new DWImageBox(img_guangdian[1]);

			m_yellow[i].setPoint(m_white[i * 2].getShowX(), m_white[i * 2].getShowY());
			m_blue[i].setPoint(m_white[i * 2 + 1].getShowX(), m_white[i * 2 + 1].getShowY());

			m_fram.addControl(m_yellow[i]);
			m_fram.addControl(m_blue[i]);
		}
	}

	/**
	 * 在圆N等分后
	 * @param control 需要放置的控件
	 * @param backControl 控件的背景圆
	 * @param radius 控件与圆心的距离
	 * @param size 将圆等分数
	 * @param index 放置在
	 */
	private void setPoint(DWControl control, DWControl backControl, int radius, int size, int index)
	{
		int m_x = backControl.getShowX() + backControl.getShowWidth() / 2;
		int m_y = backControl.getShowY() + backControl.getShowHeight() / 2;

		int targetX = m_x
				- (UITowerCarbon.sin(index * (360 / size) - (360 / size * 2) << UITowerCarbon.BITS) * radius >> UITowerCarbon.BITS);
		int targetY = m_y
				+ (UITowerCarbon.cos(index * (360 / size) - (360 / size * 2) << UITowerCarbon.BITS) * radius >> UITowerCarbon.BITS);
		control.setPoint((int) targetX - control.getShowWidth() / 2, (int) targetY - control.getShowHeight() / 2);
	}

	/**
	 * 刷新界面
	 */
	private void refreshFrame()
	{
		setremaindeMsg();
		luckStop();
		lightShop();
		m_selectImg.setShow(false);
		m_animation.setShow(false);

		if (m_giftGrid == null || m_gift_list == null)
		{
			return;
		}

		for (int i = 0; i < m_giftGrid.length; i++)
		{
			m_giftGrid[i].addObject(null);

			if (i < m_gift_list.length)
				m_giftGrid[i].addObject(m_gift_list[i]);
			else
				break;
		}
	}

	/**
	 * 显示剩余抽奖次数
	 */
	private void setremaindeMsg()
	{
		if (m_remaindeMsg == null)
		{
			m_remaindeMsg = new DWTextbox("");
			m_fram.addControl(m_remaindeMsg);
		}

		byte vip_lv = DWGameManager.getInstance().m_role.m_vip_lv;

		m_remaindeMsg.setFont(DWFont.getFont(DWFont.getDefaultFont().getFontSize() + 3));
		m_remaindeMsg.setText("<mark c=f1d315>" + (vip_lv > 0 ? "vip" + vip_lv : "非vip") + "抽奖" + m_gift_trancount
				+ "次</mark>");
		m_remaindeMsg.setNearAnchor(m_addNum, Tools.RIGHT_BOTTOM, Tools.RIGHT_TOP, 0, -5);
	}

	/**
	 * 抽奖增次
	 */
	private DWFrame m_addnum_frame;
	private DWTitle m_addnum_title;
	private DWImageBox m_addnum_close;
	private DWTextbox m_addnum_msg;
	private DWImageBox m_addnum_minus;
	private DWImageBox m_addnum_plus;
	private DWInputBox m_addnum_input;
	private DWTextbox m_addnum_numMsg;
	private DWTextbox m_addnum_feeLabel;
	private DWTextbox m_addnum_fee;
	private DWImageBox m_addnum_yuanbao;
	private DWButton m_addnum_button;
	private byte m_last_num = 1;

	private void showAddNum()
	{
		m_last_num = 1;

		if (DWControlsManager.getInstance().contains(m_addnum_frame))
			DWControlsManager.getInstance().removeControl(m_addnum_frame);

		m_addnum_frame = new DWFrame(DWGameManager.Screen_Width * 2 / 5, DWGameManager.Screen_Width * 3 / 10);

		m_addnum_title = new DWTitle("抽奖增次", m_addnum_frame);
		m_addnum_frame.addControl(m_addnum_title);

		m_addnum_close = new DWImageBox(img_close);
		m_addnum_close.setTouchZoomIn(UIFixWindow.TOUCHZOOM, UIFixWindow.TOUCHZOOM);
		m_addnum_close.setNearAnchor(m_addnum_title, Tools.RIGHT_VCENTER, Tools.RIGHT_VCENTER);
		m_addnum_close.addListener(new DWListener() {
			public void OnDoubleClick()
			{
			}

			public void OnClick()
			{
				DWControlsManager.getInstance().removeControl(m_addnum_frame);
			}
		});
		m_addnum_frame.addControl(m_addnum_close);

		DWBackground m_background = new DWBackground(m_addnum_frame.getShowWidth() - 20,
				m_addnum_frame.getShowHeight() - 40);
		m_background.setFill(true);
		m_background.setNearAnchor(m_addnum_frame, Tools.HCENTER_BOTTOM, Tools.HCENTER_BOTTOM, 0, -20);
		m_addnum_frame.addControl(m_background);

		m_addnum_msg = new DWTextbox("<mark c=FFBB11>购买节日抽奖的次数：</mark>");
		m_addnum_msg.setNearAnchor(m_addnum_title, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 30, 20);
		m_addnum_frame.addControl(m_addnum_msg);

		m_addnum_input = new DWInputBox(m_addnum_frame.getShowWidth() / 3, DWFont.getDefaultFont().getHeight() + 10,
				m_addnum_frame);
		m_addnum_input.setText("1");
		m_addnum_input.addListener(new DWListener() {
			public void OnDoubleClick()
			{
			}

			public void OnClick()
			{
				String numStr = m_addnum_input.getText();

				if (UINpcShopWindow.isNumber(numStr))
				{
					int num = Integer.parseInt(numStr);
					if (num < 0)
					{
						num = 1;
					}
					else if (num > m_gift_tranbuy)
					{
						num = m_gift_tranbuy;
					}
					m_last_num = (byte) num;
				}
				else
				{
					DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "请输入数字");
				}
				m_addnum_input.setText("" + m_last_num);
				setBuyFee();
			}
		});
		m_addnum_input
				.setNearAnchor(m_addnum_title, Tools.HCENTER_TOP, Tools.HCENTER_BOTTOM, 0, 20 + 5
						+ m_addnum_msg.getShowHeight()
						+ Math.abs((img_minus.getHeight() - m_addnum_input.getShowHeight()) / 2));
		m_addnum_frame.addControl(m_addnum_input);

		m_addnum_minus = new DWImageBox(img_minus);
		m_addnum_minus.setNearAnchor(m_addnum_input, Tools.RIGHT_VCENTER, Tools.LEFT_VCENTER, -5, 0);
		m_addnum_minus.addListener(new DWListener() {

			public void OnDoubleClick()
			{
			}

			public void OnClick()
			{
				String numStr = m_addnum_input.getText();

				if (UINpcShopWindow.isNumber(numStr))
				{
					int num = Integer.parseInt(numStr);

					if (num == 1)
					{
						num = m_gift_tranbuy;
					}
					else
					{
						num--;
					}
					m_last_num = (byte) num;
				}

				m_addnum_input.setText("" + m_last_num);
				setBuyFee();
			}
		});
		m_addnum_frame.addControl(m_addnum_minus);

		m_addnum_plus = new DWImageBox(img_plus);
		m_addnum_plus.setNearAnchor(m_addnum_input, Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER, 5, 0);
		m_addnum_plus.addListener(new DWListener() {
			public void OnDoubleClick()
			{
			}

			public void OnClick()
			{
				String numStr = m_addnum_input.getText();

				if (UINpcShopWindow.isNumber(numStr))
				{
					int num = Integer.parseInt(numStr);

					if (num == m_gift_tranbuy)
					{
						num = 1;
					}
					else
					{
						num++;
					}
					m_last_num = (byte) num;
				}

				m_addnum_input.setText("" + m_last_num);
				setBuyFee();
			}
		});
		m_addnum_frame.addControl(m_addnum_plus);

		m_addnum_numMsg = new DWTextbox("<mark c=FFBB11>今日还可增加</mark><mark c=55FF00>" + m_gift_tranbuy
				+ "</mark><mark c=FFBB11>次</mark>");
		m_addnum_numMsg.setNearAnchor(m_addnum_msg, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 10 + Math.max(m_addnum_input
				.getShowHeight(), img_minus.getHeight()));
		m_addnum_frame.addControl(m_addnum_numMsg);

		m_addnum_feeLabel = new DWTextbox("<mark c=FFBB11>需要：</mark>");
		m_addnum_feeLabel.setNearAnchor(m_addnum_numMsg, Tools.LEFT_TOP, Tools.LEFT_BOTTOM);
		m_addnum_frame.addControl(m_addnum_feeLabel);

		m_addnum_button = new DWButton("确定", img_anniu);
		m_addnum_button.setDownImage(img_anxia);
		m_addnum_button.addListener(new DWListener() {
			public void OnDoubleClick()
			{
			}

			public void OnClick()
			{
				DWControlsManager.getInstance().removeControl(m_addnum_frame);
				Tools.debugPrintln("增加次数" + m_last_num);
				DWGameManager.getInstance().getSendMessage().sendLuckDrawAdd(m_last_num);
			}
		});
		m_addnum_button.setNearAnchor(m_addnum_frame, Tools.LEFT_BOTTOM, Tools.LEFT_BOTTOM, 20, -30);
		m_addnum_frame.addControl(m_addnum_button);

		setBuyFee();

		DWControlsManager.getInstance().addControl(m_addnum_frame);
	}

	/**
	 * 购买增次剩余次数
	 */
	private void setBuyNum()
	{
		m_addnum_numMsg.setText("今日还可增加" + m_gift_tranbuy + "次");
	}

	/**
	 * 购买增次花费
	 */
	private void setBuyFee()
	{
		if (m_addnum_fee == null)
		{
			m_addnum_fee = new DWTextbox("");
		}
		if (!m_addnum_frame.contains(m_addnum_fee))
		{
			m_addnum_frame.addControl(m_addnum_fee);
		}

		if (m_addnum_yuanbao == null)
		{
			m_addnum_yuanbao = new DWImageBox(img_yuanbao);
		}
		if (!m_addnum_frame.contains(m_addnum_yuanbao))
		{
			m_addnum_frame.addControl(m_addnum_yuanbao);
		}

		m_addnum_fee.setText("<mark c=00BBFF>" + m_last_num * m_gift_money + "</mark>");
		m_addnum_fee.setNearAnchor(m_addnum_feeLabel, Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER, 10, 0);

		m_addnum_yuanbao.setNearAnchor(m_addnum_fee, Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER, 5, 0);
	}

	private boolean m_luckStart = false;
	private boolean m_luckSend = false;
	private int m_timer = 0;
	private int m_arc1_speed = 1;// /多少帧数转一次
	private int m_selctIndex = -1;

	/**
	 * 开始抽奖
	 */
	private void luckStart()
	{
		m_start.setShow(true);
		m_start.setTouch(false);
		m_timer = 0;
		m_luckStart = true;
		m_selctIndex = -1;
		m_animation.setShow(false);
		lightStar();
		
		m_gift_trancount --;
		Tools.debugPrintln("m_gift_trancount=" + m_gift_trancount);
		if (DWControlsManager.getInstance().contains(m_fram))
			setremaindeMsg();
	}

	/**
	 * 停止抽奖
	 */
	private void luckStop()
	{
		m_gift_key = null;
		m_luckStart = false;
		m_selctIndex = -1;
		m_selectImg.setShow(false);
	}

	/**
	 * 灯开始闪烁
	 */
	private boolean m_lightStar = false;
	private long m_waiteTime = 0;

	private void lightStar()
	{
		m_lightStar = true;
		m_waiteTime = 0;
		m_luckSend = false;
	}

	/**
	 * 灯停止闪烁
	 */
	private void lightShop()
	{

		m_timer = 0;
		m_lightStar = false;
		m_luckSend = false;
		m_start.setShow(false);
		m_start.setTouch(true);
		for (int i = 0; i < 10; i++)
		{
			m_yellow[i].setShow(false);
			m_blue[i].setShow(false);
		}
		m_animation.setShow(false);
	}

	/**
	 * 抽奖道具类
	 * @author Administrator
	 * 
	 */
	class GiftItem implements IIcon
	{
		public Bitmap m_icon;

		public String m_key;
		public short m_iconId;//icon
		public byte m_num; //数量

		public void recvItemFormServer(DataInputStream dis) throws IOException
		{
			m_key = dis.readUTF();
			Tools.debugPrintln("item 名称" + m_key);
			m_iconId = dis.readShort();
			Tools.debugPrintln("item 图标id" + m_iconId);
			m_icon = IconManger.getInstance().getIcon(m_iconId);
			m_num = dis.readByte();
			Tools.debugPrintln("item 数量" + m_num);
		}

		public void drawIcon(DWGraphics g, int x, int y, int w, int h, int anchor)
		{
			if (m_icon != null) {
				g.drawBitmap(m_icon, x, y, anchor);
			}
			if (m_num > 1) {
				float tempX = x - (w >> 1);
				float tempY = y + ((h >> 1) - DWFont.getDefaultFont().getHeight());
				String temp = "" + m_num;
				g.drawString(temp, Color.WHITE, tempX, tempY, 0);
			}
		}

		public void drawIcon(DWGraphics g, int x, int y, int w, int h, float scaleX, float scaleY, int anchor)
		{
		}
	}

	/**
	 * 打开抽奖界面
	 * @param dis
	 * @throws IOException
	 */
	public void readLuckDrawOpen(DataInputStream dis) throws IOException
	{
		m_gift_trancount = dis.readByte();
		Tools.debugPrintln("m_gift_trancount" + m_gift_trancount);
		m_gift_tranbuy = dis.readByte();
		m_gift_money = dis.readInt();

		m_gift_size = dis.readByte();
		Tools.debugPrintln("m_gift_size" + m_gift_size);
		m_gift_list = new GiftItem[m_gift_size];

		for (int i = 0; i < m_gift_size; i++)
		{
			m_gift_list[i] = new GiftItem();
			m_gift_list[i].recvItemFormServer(dis);
		}

		open((byte) 0);
	}

	/**
	 * 开始抽奖
	 * @param dis
	 * @throws IOException
	 */
	public void readLuckDrawResult(DataInputStream dis) throws IOException
	{
		byte state = dis.readByte();

		switch (state) {
			case 0:
				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "抽奖次数已满");
				break;
			case 1:
				m_gift_key = dis.readUTF();
				Tools.debugPrintln("m_gift_key=" + m_gift_key);
				break;
			case 2:
				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "背包已满");
				luckStop();
				lightShop();
				break;
			default:
				break;
		}

	}

	/**
	 * 请求抽奖结果道具
	 * @param dis
	 * @throws IOException
	 */
	public void readLuckDrawGetResult(DataInputStream dis) throws IOException
	{
//		byte state = dis.readByte();
//		if (state == 1)
//		{
		m_gift_trancount = dis.readByte();
		Tools.debugPrintln("m_gift_trancount=" + m_gift_trancount);
		if (DWControlsManager.getInstance().contains(m_fram))
		{
			setremaindeMsg();
		}
//		}
//		else
//			DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "抽奖次数已满");
	}

	/**
	 * 抽奖增次结果
	 * @param dis
	 * @throws IOException
	 */
	public void readLuckDrawAddResult(DataInputStream dis) throws IOException
	{
		byte state = dis.readByte();

		switch (state) {
			case 0:
				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "元宝不足");
				break;
			case 1:
				m_gift_tranbuy = dis.readByte();
				Tools.debugPrintln("m_gift_tranbuy=" + m_gift_tranbuy);
				m_gift_trancount = dis.readByte();
				Tools.debugPrintln("m_gift_trancount=" + m_gift_trancount);
				if (DWControlsManager.getInstance().contains(m_fram))
					setremaindeMsg();
				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "增次成功");
				break;
			case 2:
				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "购买次数已满");
				break;
			default:
				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "购买失败");
				break;
		}
	}

}
